package cn.edu.hpu.web;


import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.hpu.dao.GoalDao;
import cn.edu.hpu.dao.TaskDao;
import cn.edu.hpu.entity.Goal;
import cn.edu.hpu.entity.Task;
import cn.edu.hpu.utitl.RateUtitl;
import cn.edu.hpu.utitl.TimeUtitl;

public class UpdateTaskServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		String gid = request.getParameter("gid");
		String tname = request.getParameter("tname");
		String tbegintime = request.getParameter("tbegintime");
		String tendtime = request.getParameter("tendtime");
		String	tdsp = request.getParameter("tdsp");
		String tstate = request.getParameter("tstate");
		String tlevel = request.getParameter("tlevel");
		String tcname = request.getParameter("tcname");
		String tid = request.getParameter("tid");
		String tctime = TimeUtitl.getTime();
		String trate = RateUtitl.getRate(tstate);
		Task t = new Task();
		t.setGid(gid);
		t.setTbegintime(tbegintime);
		t.setTcname(tcname);
		t.setTctime(tctime);
		t.setTdsp(tdsp);
		t.setTendtime(tendtime);
		t.setTid(tid);
		t.setTlevel(tlevel);
		t.setTname(tname);
		t.setTrate(trate);
		t.setTstate(tstate);
		TaskDao td = new TaskDao();
		td.updateATaskByTid(t);
		GoalDao gd = new GoalDao();
		Goal g = gd.findAGoal(gid);
		List<Task> list = td.findALLTaskByGid(gid);
		request.setAttribute("tlist", list);
		request.setAttribute("goal", g);
		request.getRequestDispatcher("/WEB-INF/views/goaltask.jsp").forward(request, response);
	}
}
